<script setup lang="ts">
import {toView} from '@/utils/utils';
import type { Ref } from "vue";
import { getNewToken, updateGroupInfo, updateUserInfo } from "@/initHooks";
import '@/Dexie/UserDB';
import '@/Dexie/MessageDB'

const Timer:Ref<number> = ref(0);
// 初始化判断有没有登录的token 如果有且未过期延长token 并跳转至内部界面
if (localStorage['token'] && localStorage['account'] && localStorage['tokenExpireTime'] > new Date().getTime()) {
  // 异步获取新token
  getNewToken().then((timer:number)=>{
    Timer.value = timer;
  });
  // 直接跳转至内部界面
  toView('ChatView2');
}
// 更新朋友/群基础信息
updateUserInfo();
updateGroupInfo();

onMounted(() => {
  window.addEventListener('beforeunload', () => {
    if(Timer.value) {
      var a = 6;
      clearInterval(Timer.value);
    }
  });
});


</script>

<template>
  <RouterView />
</template>

<style scoped lang="less">

</style>
